<!DOCTYPE html>
<html>
	<head>
		<title>我的游记</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/userTravels.css" />
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/dialog2/dialog.min.js"></script>

		<script>
			$(function () {
				//取出当前用户
				var user=JSON.parse(sessionStorage.getItem("user"));
				//默认当前页为1
				var currentPage=1;
				//总页数
				var pages;
				//存储游记数据的数组
                var travelData=[];
				//发送ajax请求
				function query() {
					$.get("/users/"+user.id+"/travels",{currentPage:currentPage},function (data) {
					    //为了每次滑动查询的数据往上叠加(将两个数组合并到第一个数组上)
						$.merge(travelData,data.list);
						//把累加的数组转换成json格式
						var json={
							list:travelData
						}
						$(".travels").renderValues(json,{
						    getHref:function (item,value) {
                                //item就是要渲染数据的标签,那个贴了很多属性的a标签
								$(item).attr("href",$(item).data("href")+value);//动态地呈现编辑的信息,拼接上每个文章的id
                            }
						});
                        //data是返回的pageInfo里的内容
						pages=data.pages;//给总页数赋值
                    });
					//当前页加一
					currentPage++;
                }
                //默认查询第一页
				query();

				//监听鼠标滚动事件
				$(window).scroll(function () {
				    //当文档滚上去的高度+窗口的高度>=html整个文档的高度,
				    if($(document).scrollTop()+$(window).height()>=$(document).height()-1){
				        //并且当前页小于等于总页数时,执行分页查询
				        if(currentPage<=pages){
							query();
						}else{
				            $(document).dialog({
								type:'notice',
								content:'<span class="info-text">已经到底了!</span>',
								autoClose:1500
							});
						}
					}
					
                });

            });

		</script>

	</head>

	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="profiles.html">
					<span><i class="fa fa-chevron-left"></i></span>
				</a>
			</div>
			<div class="col">
				<span>我的游记</span>
			</div>
			<div class="col"></div>
		</div>
	</div>


	<div class="container travels">
		<dl class="list" render-loop="list">
			<dd>
				<!--render-key:从对象中获取指定的属性值,render-fun:渲染数据时会调用的函数-->
				<a render-key="list.id" render-fun="getHref" data-href="/mine/editTravels.html?id=">
					<img render-src="list.coverUrl">
					<h6 class="title" render-html="list.title"></h6>
					<p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
						<span class="span-right">
								  <i class="fa fa-heart"></i><span>0</span>收藏
							  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
					</p>
				</a>
			</dd>

		</dl>
	</div>

	</body>
</html>
